package cn.zwt.wolf.service.arrange;

import cn.zwt.wolf.domain.arrange.Arrange;
import cn.zwt.wolf.domain.content.Content;
import cn.zwt.wolf.repository.arrange.ArrangeRepository;
import cn.zwt.wolf.util.JPQLSearchException;
import cn.zwt.wolf.util.SearchUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.persistence.NoResultException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by zhangwt on 16-3-13.
 */
@Service
public class ArrangeService {
    @Autowired
    private ArrangeRepository arrangeRepository;
    @Autowired
    private SearchUtil searchUtil;
    private Logger logger = LoggerFactory.getLogger(ArrangeService.class);




    public Arrange findArrangeByRid(int ruleId){
        Arrange arrange =null;
        if ((Integer)ruleId==null)
            return arrange;
        String hql = "from Arrange where status = 1 and ruleId=:ruleId";
        Map<String,Object> params= new HashMap<String, Object>();
        params.put("ruleId",ruleId);
        try {
            arrange = (Arrange) searchUtil.getSingleResult(hql, params);
        } catch (JPQLSearchException e) {
            logger.error("findArrangeByrRid error :" + e.getMessage());
        }catch (NoResultException e){
            logger.error("findArrangeByrRid error :" + e.getMessage());
        }
        return arrange;
    }
    public Arrange saveOrUpdate(Arrange arrange){
        return arrangeRepository.save(arrange);
    }

}
